package com.example.wuqujingdianphone.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.wuqujingdianphone.R;
import com.example.wuqujingdianphone.bean.MySectionFenleiBean;
import com.example.wuqujingdianphone.bean.MySectionFenleiChildBean;
import com.example.wuqujingdianphone.bean.MySectionTingshuBean;
import com.example.wuqujingdianphone.bean.MySectionTingshuChildBean;

import java.util.List;

/**
 * https://github.com/CymChad/BaseRecyclerViewAdapterHelper
 */
public class SectionFenleiAdapter extends BaseSectionQuickAdapter<MySectionFenleiBean, BaseViewHolder> {

    public SectionFenleiAdapter(int layoutResId, int sectionHeadResId, List data) {
        super(layoutResId, sectionHeadResId, data);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, final MySectionFenleiBean item) {
        helper.setText(R.id.header, item.header);
        helper.setVisible(R.id.more, item.isMore());
        helper.addOnClickListener(R.id.more);
        helper.getView(R.id.more).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                headerCallBack.headerclick(item.getId(), item.header);
            }
        });
    }


    @Override
    protected void convert(BaseViewHolder helper, MySectionFenleiBean item) {
        MySectionFenleiChildBean video = (MySectionFenleiChildBean) item.t;
//        switch (helper.getLayoutPosition() % 2) {
//            case 0:
//                helper.setImageResource(R.id.iv, R.mipmap.ic_launcher);
//                break;
//            case 1:
//                helper.setImageResource(R.id.iv, R.mipmap.home_nol);
//                break;
//
//        }
        Glide.with(mContext)
                .load(video.getImg())
                .error(R.drawable.icon_book_cover_defalt)
                .placeholder(R.drawable.icon_book_cover_defalt)
                .centerCrop()
                .into((ImageView) helper.getView(R.id.image));
        helper.setText(R.id.book_name, video.getName());
    }

    private HeaderCallBack headerCallBack;

    public void setHeaderCallBack(HeaderCallBack headerCallBack) {
        this.headerCallBack = headerCallBack;
    }

    public interface HeaderCallBack {
        void headerclick(String id, String title);
    }
}
